package com.zhiyou.servlet;

import com.zhiyou.model.House;
import com.zhiyou.service.ContractService;
import com.zhiyou.service.impl.ContractServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class ContractAddServlet extends HttpServlet {
    private ContractService cS=new ContractServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        System.out.println("添加成功");
        String cnum =req.getParameter("cnum");
        int chid = Integer.parseInt(req.getParameter("chid"));
        int clid = Integer.parseInt(req.getParameter("clid"));
        String ctime = req.getParameter("ctime");
        String cstartTime = req.getParameter("cstartTime");
        String cendTime = req.getParameter("cendTime");
        String ctotalMoney = req.getParameter("ctotalMoney");
        int cpayType = Integer.parseInt(req.getParameter("cpayType"));

        if(cnum!=""&&chid!=0&&clid!=0&&ctime!=""&&cstartTime!=""&&cendTime!=""&&ctotalMoney!=""&&cpayType!=0){
            cS.addNew(cnum,chid,clid,ctime,cstartTime,cendTime,ctotalMoney,cpayType);
            //new HouseDao().addNew(haddress,hfloor,hroomNum,harea,hdir,hdeco,hair,hprice,hrentStatus,himage,haddTime,hupdateTime);
//            List<House> houses = hS.getHouse(1,3);
//            req.getSession().setAttribute("houses",houses);
            resp.sendRedirect(req.getContextPath()+"/user/contract?pageNo="+req.getParameter("pageNo"));
        }else{
            req.setAttribute("err","注册失败,请将信息填写完整");
            resp.sendRedirect(req.getContextPath()+"/view/contract/add.jsp");
        }

    }



}
